package com.glodon.zhuanli.config;

import com.glodon.framework.web.config.shiro.SecureFilter;
import com.glodon.framework.web.config.shiro.filter.LoginFormAuthenticationFilter;
import com.glodon.framework.web.config.shiro.filter.support.VCodeValidator;
import com.glodon.infrastructure.config.BaseSecurityConfig;
import com.glodon.zhuanli.front.ZLUserRealm;
import org.apache.shiro.realm.AuthorizingRealm;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.Map;

/**
 * 系统安全过滤
 */
@Configuration
public class ZhuanliSecurityConfig extends BaseSecurityConfig {

    @Override
    public AuthorizingRealm userRealm(){
        return new ZLUserRealm() ;
    }

    @Override
    protected void configFilterChainDefinition(Map<String, String> linkedDefinitionMap){
        super.configFilterChainDefinition(linkedDefinitionMap) ;

        //登陆页面的权限验证
//        linkedDefinitionMap.put("/login" , "loginauth") ;

        linkedDefinitionMap.put("/insdep/**" , "anon") ;

        linkedDefinitionMap.put("/local/**" , "anon") ;

        linkedDefinitionMap.put("/front/**" , "anon") ;

        //默认其他页面只有登录的用户才能查看
        linkedDefinitionMap.put("/**" , "anon") ;

        //默认其他页面只有登录的用户才能查看
//        linkedDefinitionMap.put("/**" , "userajax") ;
    }

    @Override
    protected void configShiroFilters(Map<String, Filter> filters){
        super.configShiroFilters(filters);

        LoginFormAuthenticationFilter loginAuthFilter =
                (LoginFormAuthenticationFilter)filters.get(SecureFilter.loginauth.name()) ;
        //启用验证码
        loginAuthFilter.addAuthenticateValidator( new VCodeValidator() ) ;
    }

}
